package com.suxin.predicate.predicate;

import java.util.function.Consumer;

/**
 * @author Tang
 * @classname ConsumerPredicate
 * @description [  ]
 * @date 2022/11/2 10:18
 */
public class ConsumerPredicate<T> implements Consumer<T> {

    private Consumer<T> tConsumer;

    private final DefaultPredicate<T> defaultPredicate;

    public ConsumerPredicate(DefaultPredicate<T> defaultPredicate) {
        this.defaultPredicate = defaultPredicate;
    }

    public ConsumerPredicate<T> addConsumer(Consumer<T> tConsumer) {
        this.tConsumer = tConsumer;
        return this;
    }

    @Override
    public void accept(T t) {
        if (defaultPredicate.test(t)) {
            this.tConsumer.accept(t);
        }
    }
}
